package dkbta.ontology.values;

import dkbta.ontology.loading.OntologyException;
import dkbta.util.time.TimeUnit;

/**
 * A numeric range represents percent values (bounded by [0,100])
 * 
 * @author Uri Kanonov
 */
public class PercentValues extends NumericValues{
	/**
	 * Constructs a NumericValues object with the given parameters
	 * 
	 * @param minE The lower bound with equality
	 * @param min The lower bound without equality
	 * @param maxE The upper bound with equality
	 * @param max The upper bound without equality
	 * @param timeUnit The time unit per which the values are (if any - i.e. if they
	 *        represent rates)
	 * @throws OntologyException
	 */
	public PercentValues(String minE, String min, String maxE, String max,
		TimeUnit timeUnit) throws OntologyException{
		super(minE, min, maxE, max, timeUnit);
		if (_min < 0 || _max > 100){
			throw new OntologyException("Illegal min or max values: " + toString()
					+ ": must be in the range [0, 100]");
		}
	}

	@Override
	protected double parseMaxValue(String max, TimeUnit timeUnit)
			throws NumberFormatException{
		double maxVal = super.parseMaxValue(max, timeUnit);
		if (Double.isInfinite(maxVal)){
			maxVal = 100;
		}
		return maxVal;
	}

	@Override
	protected double parseMinValue(String min, TimeUnit timeUnit)
			throws NumberFormatException{
		double minVal = super.parseMinValue(min, timeUnit);
		if (Double.isInfinite(minVal)){
			minVal = 0;
		}
		return minVal;
	}
}
